<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
        <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
          <t-col :span="11" class="query-form-inline">
            <t-form-item label="登录地址" name="ipaddr">
              <t-input
                v-model="queryParams.ipaddr"
                placeholder="请输入登录地址"
                clearable
                style="width: 240px;"
              />
            </t-form-item>
            <t-form-item label="用户名称" name="userName">
              <t-input
                v-model="queryParams.userName"
                placeholder="请输入用户名称"
                clearable
                style="width: 240px;"
              />
            </t-form-item>
            <t-form-item label="状态" name="status">
              <t-select
                v-model="queryParams.status"
                placeholder="登录状态"
                clearable
                style="width: 240px"
                :options="dict.type.sys_common_status"
              >
              </t-select>
            </t-form-item>
          </t-col>
          <t-col :span="1" class="operation-container">
            <t-button theme="primary" type="submit"> 查询</t-button>
            <t-button theme="default" variant="outline" type="reset">重置</t-button>
          </t-col>
        </t-row>
    </t-form>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #status="{row}">
        {{ row.status | filterByDict(dict.type.sys_common_status) }}
      </template>
    </t-table>
  </div>
</template>

<script>
export default {
  name: "login-log-index",
  dicts: ["sys_common_status"],
  data(){
    return {
      data: [],
      columns: [
        {
          colKey: "userName",
          title: "用户名称",
          align: "center",
        },
        {
          colKey: "ipaddr",
          title: "登录地址",
          align: "center",
        },
        {
          colKey: "status",
          title: "登录状态",
          align: "center",
        },
        {
          colKey: "msg",
          title: "描述",
          align: "center",
        },
        {
          colKey: "accessTime",
          title: "登录时间",
          align: "center",
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ipaddr: '',
        userName: '',
        status: '',
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created(){
    this.getList();
  },
  methods:{
    getList(){
      this.dataLoading = true;
      this.$api.system.log.login(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    }
  }
}
</script>

<style scoped>

</style>
